package com.pool.common;

/**
 * Class representing an object holding two elements.
 *
 * @author claveld@gmail.com (David Clavel)
 * @param <T> Type of the first element
 * @param <V> Type of the second element
 */
public class Pair<T, V> {
  private final T first;
  private final V second;

  public Pair(T first, V second) {
    this.first = first;
    this.second = second;
  }

  public T getFirst() {
    return first;
  }

  public V getSecond() {
    return second;
  }

  public static <T, V> Pair<T, V> copyFrom(Pair<T, V> pair) {
    return Pair.of(pair.getFirst(), pair.getSecond());
  }

  public static <T, V> Pair<T, V> of(T t, V v) {
    return new Pair<T, V>(t, v);
  }

  @SuppressWarnings("unchecked")
  @Override
  public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null)
      return false;
    if (getClass() != o.getClass())
      return false;
    final Pair<T, V> other = (Pair<T, V>) o;
    if (first == null) {
      if (other.first != null)
        return false;
    } else if (!first.equals(other.first))
      return false;
    if (second == null) {
      if (other.second != null)
        return false;
    } else if (!second.equals(other.second))
      return false;
    return true;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((first == null) ? 0 : first.hashCode());
    result = prime * result + ((second == null) ? 0 : second.hashCode());
    return result;
  }
}
